package demo03;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class C3P0Demo01 {
    public static void main(String[] args) throws SQLException {
        //创建c3p0连接池对象
        ComboPooledDataSource dataSource = new ComboPooledDataSource();

        //获取数据库连接对象进行使用
        Connection con = dataSource.getConnection();

        //查询全部学生信息
        String sql="SELECT * FROM student";
        PreparedStatement pst = con.prepareStatement(sql);
        ResultSet rs = pst.executeQuery();

        while (rs.next()){
            System.out.println(rs.getInt("sid") + "\t" + rs.getString("name") + "\t"
                    + rs.getInt("age") + "\t" + rs.getDate("birthday"));
        }

        //释放资源
        rs.close();
        pst.close();
        con.close();
    }
}
